package  wibrst.time{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	/**
	 * ...
	 * @author wibrst@qq.com
	 */
	public class RdmTimer extends EventDispatcher{
		
		static public const EVT_TIMER_POINT:String = "EVT_TIMER_POINT";
		
		/**
		 * 
		 * @param	nBase		interval second
		 * @param	nRange	range second
		 */
		public function RdmTimer( nBase:Number, nRange:Number ) {
			this._nBase = nBase;
			this._nRange = nRange;
			
			this._timer = new Timer( 0 );
			this._timer.addEventListener( TimerEvent.TIMER, timerIntvHandler );
			this._timer.delay = this.nRdmTime;
			this._timer.start();
		}
		
		public function dispose():void {
			this._timer.removeEventListener( TimerEvent.TIMER, timerIntvHandler );
		}
		
		private function get nRdmTime():Number {
			return ( this._nBase + Math.random() * this._nRange ) * 1000;
		}
		
		private function timerIntvHandler( e:TimerEvent ):void {
			super.dispatchEvent( new Event( EVT_TIMER_POINT ) );
			this._timer.delay = this.nRdmTime;
		}
		
		private var _timer:Timer;
		private var _nRange:Number;
		private var _nBase:Number;
	}

}